// pages/detail/detail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    value:{},
    playStates:{},
    prevId:""
  },
  onLoad: function (options) {
    console.log(options.id);
    wx.request({
      url: `http://192.168.4.18:3000/playlist/detail?id=${options.id}`,
      data: {},
      method: 'GET',
      success: (res)=>{
        console.log(typeof res.data.playlist.playCount);
        let num = res.data.playlist.playCount;

        // res.data.playlist.playCount = this.deal(res.data.playlists.playCount);
        res.data.playlist.playCount = this.deal(num);


        res.data.playlist.tracks.forEach(res=>{
          res.dt = this.time(res.dt);
          // res.dt = this.minNumber(res.dt);
        })
        this.setData({
          value:res.data.playlist
        })
        console.log(this.data.value.tracks);
      }
    })
  },
  handMusic(Event){
    // 获取每个块中的播放键的自定义属性id
    let id = Event.currentTarget.dataset.id;
    let playStates = this.data.playStates;
    /* 当前项目id和点击之后的id值不同的情况 */
    console.log(id);
    playStates[id] = !playStates[id]; 
    for(let key in playStates){
      if(key != id){
        playStates[key] = false;
      }
    }
    console.log(playStates);
    this.setData({
      playStates,
      prevId:id
    })
  },
  deal(num){
    if(num>=100000000){
      num = Math.floor(num/100000000)+"亿"
    }else if(num>=10000){
      num = Math.floor(num/10000)+"万"
    }
    return num;
  },

  time(dt){
    var min = this.minNumber(Math.floor(dt/1000/60));
    var seconds = this.minNumber(Math.floor(dt/1000%60));
    dt = String(min)+":"+String(seconds);
    return dt
  },
// 补零
  minNumber(num){
    if(num<10){
        num = "0"+num;
    }
    return num;
  }
})